package CodeTop.无重复字符的最长子串;

// https://leetcode.cn/problems/longest-substring-without-repeating-characters/
class Solution {
    public int lengthOfLongestSubstring(String s) {
        char[] cs = s.toCharArray();
        int[] map = new int[128]; // 记录字符的出现次数
        int res = 0;
        for (int l = 0, r = 0; r < cs.length; r++) {
            map[cs[r]]++;
            while (map[cs[r]] > 1) map[cs[l++]]--;
            res = Math.max(res, r - l + 1);
        }
        return res;
    }
}